//
//  LHSightTableViewCell.m
//  Knight_Tour
//
//  Created by Bruce_Lin on 15/5/14.
//  Copyright (c) 2015年 TouchOne. All rights reserved.
//

#import "LHSightTableViewCell.h"

@interface LHSightTableViewCell ()
@end

@implementation LHSightTableViewCell

- (void)dealloc
{
    [_titleImage release];
    [_titleLabel release];
    [_introduceLabel release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self createView];
    }
    return self;
}

- (void)createView
{
    self.titleImage = [[UIImageView alloc]init];
    [self.contentView addSubview:_titleImage];
    [_titleImage release];
    
    self.titleLabel = [[UILabel alloc]init];
    _titleLabel.numberOfLines = 0;
    [self.contentView addSubview:_titleLabel];
    [_titleLabel release];
    
    self.introduceLabel = [[UILabel alloc]init];
    _introduceLabel.numberOfLines = 0;
    [self.contentView addSubview:_introduceLabel];
    [_introduceLabel release];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    [self.titleImage setFrame:CGRectMake(10, 10, self.contentView.frame.size.width - 20, self.frame.size.height / 3)];
    
    [self.titleLabel setFrame:CGRectMake(10, _titleImage.frame.size.height + 20, _titleImage.frame.size.width, [[self class]myHeightWithText:self.titleText])];
    
    [self.introduceLabel setFrame:CGRectMake(10, _titleLabel.frame.origin.y +  _titleLabel.frame.size.height + 10, _titleLabel.frame.size.width, [[self class]myHeightWithText:self.introduceText])];
    _introduceLabel.text = self.introduceText;
}

+ (CGFloat)myHeightWithText:(NSString *)text
{
    // 创建一个字典保存文本属性
    // 保存文本文字大小
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:17], NSFontAttributeName, nil];
    // 预设一个尺寸, 文本最大不会超过这个尺寸
    CGSize size = CGSizeMake([UIScreen mainScreen].bounds.size.width - 20, 1000);
    // 根据文本信息获得一个CGRect
    // 参数1:尺寸范围  参数2:文本属性  参数3:按照什么方式获取Rect  参数4:nil
    CGRect rect = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    
    return rect.size.height;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}



@end
